<!--
 * @Description: 深化设计策划书管理
 * @Author: wind-lc
 * @version: 1.0
 * @Date: 2021-08-18 10:34:47
 * @LastEditTime: 2021-08-31 18:52:16
 * @FilePath: \cscec-pms-admin\src\views\design\deepDesign\planningManagement\index.vue
-->
<template>
  <!-- 深化设计策划书管理 -->
  <base-breadcrumb class="flexMemberInfo-container">
    <!-- 搜索 -->
    <searchData
      :search-data="searchOption"
      @search="search"
    />
    <!-- 搜索 -->
    <a-card>
      <div class="table-operator">
        <!-- <title-name title="深化设计策划书列表" /> -->
      </div>
      <!-- 表格操作 -->
      <list-table
        ref="table"
        :columns="columns"
        :request="loadData"
        :is-show-count-bar="false"
      >
        <template slot="prefix">
          <a-button
            v-btnPermission="'ds_023_add_01'"
            type="primary"
            icon="plus"
            @click="handleAdd"
          >
            新增深化设计策划书
          </a-button>
        </template>
        <template slot="bottom">
          <div class="pub-table-select-count">
            <a-icon
              type="info-circle"
              theme="twoTone"
            />
            <span style="margin-right: 12px">
              深化设计策划书总数：<span class="totalNum">{{ statistics.total || 0 }} 个</span> |
              待提交审核：<span class="totalNum">{{ statistics.draftNum || 0 }} 个</span> |
              审核中：<span class="totalNum">{{ statistics.submittedNum || 0 }} 个</span> |
              审核不通过：<span class="totalNum">{{ statistics.rejectedNum || 0 }} 个</span> |
              审核通过：<span class="totalNum">{{ statistics.passNum || 0 }} 个</span> |
              一次性审核通过：<span class="totalNum">{{ statistics.firstPassNum || 0 }} 个</span> |
              一次性审核通过率：<span class="totalNum">{{ statistics.firstPassRate || 0 }}</span>
            </span>
          </div>
        </template>
        <span
          slot="operation"
          slot-scope="text,record"
        >
          <MoreButton>
          <template >
            <a @click="handleOperation(record,'detail')" v-btnPermission="'ds_023_loo_02'">查看</a>
            <a-divider type="vertical" />
          </template>
          <template
            v-if="record.statusCode === '0' || record.statusCode === '3'"

          >
            <a @click="handleOperation(record,'update')"  v-btnPermission="'ds_023_edi_03'">编辑</a>
            <a-divider type="vertical" />
          </template>
          <template
            v-if="record.statusCode === '0'"

          >
            <a @click="handleOperation(record,'delete')"  v-btnPermission="'ds_023_del_04'">删除</a>
            <a-divider
              v-if="record.statusCode !== '0'"
              type="vertical"
            />
          </template>
          <template v-if="record.statusCode !== '0'">
            <a @click="handleOperation(record,'approva')">审核信息</a>
          </template>
            </MoreButton>
        </span>
      </list-table>
      <!-- 表格操作 -->
    </a-card>
  </base-breadcrumb>
  <!-- 深化设计策划书管理 -->
</template>
<script>
import { searchOption, columns } from './model.js'
import planningManagement from '@/api/design/deepDesign/planningManagement'
export default {
  name: 'PlanningManagement',
  components: {},
  data() {
    return {
      // 搜索选项
      searchOption,
      // 表头
      columns,
      // 查询参数
      searchData: {},
      // 统计
      statistics: {},
      // 表数据加载
      loadData: async (q) => {
        const params = Object.assign(q, this.searchData)
        if (this.searchData?.createTime?.length > 0) {
          params.startDate = this.searchData.createTime[0].format('YYYY-MM-DD') || void 0
          params.endDate = this.searchData.createTime[1].format('YYYY-MM-DD') || void 0
        }
        delete params.createTime
        const res = await planningManagement.list(params)
        const total = res.totalSize
        // 统计
        const { data } = await planningManagement.statistics(params)
        this.statistics = data
        this.statistics.total = total
        if (res.code === 200) {
          return { code: 200, data: res.data, ...res }
        }
        return {
          code: 200,
          data: []
        }
      }
    }
  },
  created() {
    this.getDesignType()
  },
  methods: {
    /**
     * @description: 项目设计管理类别
     * @param {void}
     * @return {void}
     */
    async getDesignType() {
      const { data } = await planningManagement.getDesignType({ type: 9 })
      this.searchOption[4].data = this.getChangeDatatTypes(data) || []
    },
    /**
     * @description: 搜索
     * @param {Object} value 搜索数据
     * @return {Void}
     */
    search(value) {
      this.searchData = value || {}
      if(this.searchData.isAdopt) {
        this.searchData.isAdopt = Number(this.searchData.isAdopt)
      }
      this.$refs.table.getData(null, true)
    },
    /**
     * @description: 新增
     * @param {void}
     * @return {void}
     */
    handleAdd() {
      this.$router.push({
        path: '/project/design/deepDesign/planningManagement/form',
        query: {
          pageType: 'add'
        }
      })
    },
    /**
     * @description: 会议操作
     * @param {object} record 行数据
     * @param {string} pageType 页面类型
     * @return {void}
     */
    handleOperation(record, pageType) {
      switch (pageType) {
        case 'detail':
          this.$router.push({
            path: `/project/design/deepDesign/planningManagement/form`,
            query: {
              id: record.id,
              pageType
            }
          })
          break
        case 'update':
          this.$router.push({
            path: `/project/design/deepDesign/planningManagement/form`,
            query: {
              id: record.id,
              pageType
            }
          })
          break
        case 'delete':
          const vm = this
          vm.$confirm({
            title: '温馨提示',
            content: `确认删除？`,
            okText: '确认',
            okType: 'danger',
            cancelText: '取消',
            async onOk() {
              planningManagement.delete({ id: record.id }).then(({ code, message }) => {
                if (code === 200) {
                  vm.$message.success('删除成功')
                  vm.$refs.table.getData(null, true)
                } else {
                  vm.$message.warning(message)
                }
              })
            }
          })
          break
        case 'approva':
          this.$bus.$emit('showApprovalDetailsDialog', record.id)
          break
      }
    }
  }
}
</script>
<style lang="less" scoped>
</style>
